/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pratica7;

import java.util.AbstractMap;
import java.util.HashMap;

/**
 *
 * @author diego
 */
public class Peso {
    
    public Integer tempo, distancia;

    public Peso(Integer tempo, Integer distancia) {
        this.tempo = tempo;
        this.distancia = distancia;
    }

    public static int compare(Object t, Object t1) {
        Peso p = (Peso) t;
        Peso p1 = (Peso) t1;
        return (p.tempo < p1.tempo ? -1 : (p.tempo == p1.tempo ? (p.distancia < p1.distancia ? -1 : (p.distancia == p1.distancia ? 0 : 1)) : 1));
    }
    
    public static Peso sum (Peso first, Peso second) {
        return new Peso(first.tempo + second.tempo, first.distancia + second.distancia);
    }
    
    public static final Peso infinity = new Peso(Integer.MAX_VALUE, Integer.MAX_VALUE);
    public static final Peso zero = new Peso(0, 0);

    public static Peso extractWeight(Vertice v1, Vertice v2, HashMap<AbstractMap.SimpleEntry<Vertice, Vertice>, Peso> weights) {
        AbstractMap.SimpleEntry<Vertice, Vertice> pair = new AbstractMap.SimpleEntry<>(v1, v2);
        return weights.get(pair);
    }

    @Override
    public String toString() {
        return "(" + "tempo=" + tempo + ", distancia=" + distancia + ')';
    }
    
}
